package com.ksyun.ks3.demo;

import com.ksyun.ks3.dto.AccessControlList;
import com.ksyun.ks3.dto.CannedAccessControlList;
import com.ksyun.ks3.dto.Grant;
import com.ksyun.ks3.dto.GranteeId;
import com.ksyun.ks3.dto.Permission;
import com.ksyun.ks3.service.request.PutBucketACLRequest;

/**
 * @author lijunwei[lijunwei@kingsoft.com]  
 * 
 * @date 2014年11月25日 上午11:21:32
 * 
 * @description 设置bucket的访问权限
 **/
public class PutBucketAclDemo extends AbstractDemo{
	public void putBucketAclWithCannedAcl(){
		PutBucketACLRequest request = new PutBucketACLRequest("test.bucket");
		//设为私有
		request.setCannedAcl(CannedAccessControlList.Private);
		//设为公开读 
		//request.setCannedAcl(CannedAccessControlList.PublicRead);
		//设为公开读写
		//request.setCannedAcl(CannedAccessControlList.PublicReadWrite);
		client.putBucketACL(request);
	}
	
	public void putBucketAclWithAcl(){
		PutBucketACLRequest request = new PutBucketACLRequest("test.bucket");

		AccessControlList acl = new AccessControlList();
		//设置用户id为12345678的用户对bucket的读权限
		Grant grant1 = new Grant();
		grant1.setGrantee(new GranteeId("12345678"));
		grant1.setPermission(Permission.Read);
		acl.addGrant(grant1);
		//设置用户id为123456789的用户对bucket完全控制
		Grant grant2 = new Grant();
		grant2.setGrantee(new GranteeId("123456789"));
		grant2.setPermission(Permission.FullControl);
		acl.addGrant(grant2);
		//设置用户id为12345678910的用户对bucket的写权限
		Grant grant3 = new Grant();
		grant3.setGrantee(new GranteeId("12345678910"));
		grant3.setPermission(Permission.Write);
		acl.addGrant(grant3);
		request.setAccessControlList(acl);
		
		client.putBucketACL(request);
	}
}
